package com.example.lib;

public abstract class Duck  {
    public void swim(){
        System.out.println("i can swim");
    };
    public abstract void display();

    FlyBehavior flyBehavior;
    QuackBehavior quackBehavior;

    public void setFlyBehavior(FlyBehavior fb) {
        this.flyBehavior = fb;
    }
    public void setQuackBehavior(QuackBehavior qb) {
        this.quackBehavior = qb;
    }

    public void performQuack() {
        if (quackBehavior!=null) {
            quackBehavior.quack();
        }
    }
    public void performFly() {
        if (flyBehavior!=null) {
            flyBehavior.fly();
        }
    }

    public static void main(String[] args) {
        Duck mallard = new MallardDuck();
        mallard.display();
        mallard.performFly();
        mallard.performQuack();
        mallard.setFlyBehavior(new FlyNoWay());
        mallard.performFly();
    }
}




